/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fanor.entidades;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author JOSUÉ
 */
@Entity
@Table(name = "filme", catalog = "video_locadora", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Filme.findAll", query = "SELECT f FROM Filme f"),
    @NamedQuery(name = "Filme.findByIdFilme", query = "SELECT f FROM Filme f WHERE f.idFilme = :idFilme"),
    @NamedQuery(name = "Filme.findByTitulo", query = "SELECT f FROM Filme f WHERE f.titulo = :titulo"),
    @NamedQuery(name = "Filme.findByDuracao", query = "SELECT f FROM Filme f WHERE f.duracao = :duracao"),
    @NamedQuery(name = "Filme.findByPreco", query = "SELECT f FROM Filme f WHERE f.preco = :preco")})
public class Filme implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_filme", nullable = false)
    private Long idFilme;
    @Size(max = 45)
    @Column(name = "titulo", length = 45)
    private String titulo;
    @Lob
    @Column(name = "capa")
    private byte[] capa;
    @Size(max = 45)
    @Column(name = "duracao", length = 45)
    private String duracao;
    @Lob
    @Size(max = 65535)
    @Column(name = "descricao", length = 65535)
    private String descricao;
    @Basic(optional = false)
    @NotNull
    @Column(name = "preco", nullable = false)
    private double preco;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "filmeIdFilme")
    private Collection<ReservaFilme> reservaFilmeCollection;
    @JoinColumn(name = "midia_id_midia", referencedColumnName = "id_midia", nullable = false)
    @ManyToOne(optional = false)
    private Midia midiaIdMidia;
    @JoinColumn(name = "categoria_id_categoria", referencedColumnName = "id_categoria", nullable = false)
    @ManyToOne(optional = false)
    private Categoria categoriaIdCategoria;

    public Filme() {
    }

    public Filme(Long idFilme) {
        this.idFilme = idFilme;
    }

    public Filme(Long idFilme, double preco) {
        this.idFilme = idFilme;
        this.preco = preco;
    }

    public Long getIdFilme() {
        return idFilme;
    }

    public void setIdFilme(Long idFilme) {
        this.idFilme = idFilme;
    }

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }

    public byte[] getCapa() {
        return capa;
    }

    public void setCapa(byte[] capa) {
        this.capa = capa;
    }

    public String getDuracao() {
        return duracao;
    }

    public void setDuracao(String duracao) {
        this.duracao = duracao;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public double getPreco() {
        return preco;
    }

    public void setPreco(double preco) {
        this.preco = preco;
    }

    @XmlTransient
    public Collection<ReservaFilme> getReservaFilmeCollection() {
        return reservaFilmeCollection;
    }

    public void setReservaFilmeCollection(Collection<ReservaFilme> reservaFilmeCollection) {
        this.reservaFilmeCollection = reservaFilmeCollection;
    }

    public Midia getMidiaIdMidia() {
        return midiaIdMidia;
    }

    public void setMidiaIdMidia(Midia midiaIdMidia) {
        this.midiaIdMidia = midiaIdMidia;
    }

    public Categoria getCategoriaIdCategoria() {
        return categoriaIdCategoria;
    }

    public void setCategoriaIdCategoria(Categoria categoriaIdCategoria) {
        this.categoriaIdCategoria = categoriaIdCategoria;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFilme != null ? idFilme.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Filme)) {
            return false;
        }
        Filme other = (Filme) object;
        if ((this.idFilme == null && other.idFilme != null) || (this.idFilme != null && !this.idFilme.equals(other.idFilme))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return titulo;
    }
    
}
